package initialize

import (
	"gitee.com/g-qs/gin-vue-admin/server/model/disease"
	"gitee.com/g-qs/gin-vue-admin/server/model/health/request"
	"gitee.com/g-qs/gin-vue-admin/server/model/user"
	"os"

	"gitee.com/g-qs/gin-vue-admin/server/global"
	"gitee.com/g-qs/gin-vue-admin/server/model/example"
	"gitee.com/g-qs/gin-vue-admin/server/model/system"

	"gitee.com/g-qs/gin-vue-admin/server/model/catering"
	"gitee.com/g-qs/gin-vue-admin/server/model/feedback"
	"gitee.com/g-qs/gin-vue-admin/server/model/health"
	"gitee.com/g-qs/gin-vue-admin/server/model/hierarchy"
	"gitee.com/g-qs/gin-vue-admin/server/model/manager"
	"gitee.com/g-qs/gin-vue-admin/server/model/public"
	"gitee.com/g-qs/gin-vue-admin/server/model/structure"
	"go.uber.org/zap"
	"gorm.io/gorm"
)

func Gorm() *gorm.DB {
	switch global.GVA_CONFIG.System.DbType {
	case "mysql":
		return GormMysql()
	case "pgsql":
		return GormPgSql()
	case "oracle":
		return GormOracle()
	case "mssql":
		return GormMssql()
	case "sqlite":
		return GormSqlite()
	default:
		return GormMysql()
	}
}

func RegisterTables() {
	db := global.GVA_DB
	err := db.AutoMigrate(

		system.SysApi{},
		system.SysUser{},
		system.SysBaseMenu{},
		system.JwtBlacklist{},
		system.SysAuthority{},
		system.SysDictionary{},
		system.SysOperationRecord{},
		system.SysAutoCodeHistory{},
		system.SysDictionaryDetail{},
		system.SysBaseMenuParameter{},
		system.SysBaseMenuBtn{},
		system.SysAuthorityBtn{},
		system.SysAutoCode{},
		system.SysExportTemplate{},
		system.Condition{},

		example.ExaFile{},
		example.ExaCustomer{},
		example.ExaFileChunk{},
		example.ExaFileUploadAndDownload{},
		hierarchy.LevelOne{},
		hierarchy.LevelTwo{},
		hierarchy.LevelThree{},
		hierarchy.FdArticleAudio{},
		hierarchy.FdArticleGraphic{},
		hierarchy.FdArticleVideo{},
		hierarchy.Comment{},
		hierarchy.FdArticleLike{},
		hierarchy.FdArticleCollect{},
		health.Physique{},
		health.Disease{},
		health.Shipu{},
		feedback.Feedback{},
		request.PhysiqueArticle{},
		request.DiseaseArticle{},
		health.FdEfficacy{},
		health.FdJq{},
		request.FdEfficacyArticle{},
		request.FdJqArticle{},
		catering.Food{},
		public.Message{},
		public.UserMessage{},
		user.Vip{}, health.HealthQAndA{},
		health.HealthQuestion{},
		structure.ServiceStationArticle{},
		disease.OpenLog{},
		manager.FdHealthManager{}, manager.FdHealthManagerRegister{}, manager.FdHealthManagerAudit{}, user.UserBindManage{}, manager.MessageRemind{},
	)
	if err != nil {
		global.GVA_LOG.Error("register table failed", zap.Error(err))
		os.Exit(0)
	}
	global.GVA_LOG.Info("register table success")
}
